<?php
class LoginAction extends Action{
	/**
	 * 显示登录模板
	 */
	public function index(){
		$this->display();
	}
	/**
	 * 登录处理
	 */
	public function login(){
		if(!$this->isPost()){
			halt('页面不存在');
		}
		if($this->_post('verify','md5')!=$_SESSION['verify']){
			$this->error('验证码错误');
		};
		$name=htmlspecialchars($_POST['username']);
		$pwd=md5($_POST['pwd']);
		$db=M('admin');
		$where=array('username'=>$name);
		$user=$db->where($where)->find();
		if(!$user  || !$user['pwd']=$pwd){
			$this->error('用户名或密码错误');
		}
		if($user['lock']){
			$this->error('用户已经被锁定');
		}
		$_SESSION['adminname']=$user['username'];
		$_SESSION['aid']=$user['id'];
		redirect(U('Index/index'));

	}
	public function verify(){
		import('ORG.Util.Image');
		Image::buildImageVerify();
	}
}
?>